package com.mzy.redis.service.impl;

import com.mzy.redis.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;


@Service
public class OrderServiceImpl implements OrderService {

    public static final String ORDER_KEY = "ord:";

    @Resource
    private RedisTemplate redisTemplate;

    // @Resource
    // private StringRedisTemplate stringRedisTemplate;
    @Override
    public void addOrder() {
        int keyId = ThreadLocalRandom.current().nextInt(1000);
        String serialNO = UUID.randomUUID().toString();
        String key = ORDER_KEY + keyId;
        String value = "京东订单" + serialNO;
        redisTemplate.opsForValue().set(key, value);
        System.out.println("***key" + key);
        System.out.println("***value" + value);
    }

    @Override
    public String getOrderById(Long orderId) {
        return (String) redisTemplate.opsForValue().get(ORDER_KEY + orderId);
    }
}
